<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="test"><span id="span1">foo</span><span>bar</span></div>
<div id="console"></div>
<script>
var s = window.getSelection();
var testDiv = document.getElementById("test");
var span1 = document.getElementById("span1");

function log(str) {
    var li = document.createElement("li");
    li.appendChild(document.createTextNode(str));
    document.getElementById("console").appendChild(li);
}

var r = document.createRange();

// select span1
r.setStart(test, 0);
r.setEnd(test, 1);
s.addRange(r);

// replace the selection with span1's text node children
s.selectAllChildren(span1.firstChild);
shouldBe('s.anchorNode', 'span1.firstChild');
shouldBe('s.anchorOffset', '0');
shouldBe('s.focusNode', 'span1.firstChild');
shouldBe('s.focusOffset', '0'); // Strange, but matches Firefox

// replace the selection with span1's children
s.selectAllChildren(span1);
shouldBe('window.getSelection().toString()', '"foo"');

// replace the selection with test's children
s.selectAllChildren(test);
shouldBe('window.getSelection().toString()', '"foobar"');

// call with types other than Node
shouldThrow('s.selectAllChildren(null)');
shouldThrow('s.selectAllChildren(window)');
shouldThrow('s.selectAllChildren("")');
</script>
</body>
</html>
